package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.file.FileUploadUtils;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.MbAdvertising;
import com.library.framework.config.CosConfig;
import com.library.framework.manager.CosUploadManager;
import com.library.service.IMbAdvertisingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Objects;


/**
 * 广告管理 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 * @blame Android Team
 */
@RestController
@RequestMapping("/library/mbAdvertising")
@SuppressWarnings("all")
public class MbAdvertisingController extends BaseController {
    private String prefix = "business/mobile/mbAdvertising";
    private String cosPrefix = "/advertising/";
    @Autowired
    private CosConfig cosConfig;
    @Autowired
    private IMbAdvertisingService mbAdvertisingService;


    /**
     * 查询广告管理列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbAdvertising:list')")
    @GetMapping("/list")
    public TableDataInfo list(MbAdvertising mbAdvertising) {
        startPage();
        List<MbAdvertising> list = mbAdvertisingService.selectMbAdvertisingList(mbAdvertising);
        return getDataTable(list);
    }


    /**
     * 导出广告管理列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MbAdvertising mbAdvertising) {
        List<MbAdvertising> list = mbAdvertisingService.selectMbAdvertisingList(mbAdvertising);
        ExcelUtil<MbAdvertising> util = new ExcelUtil<MbAdvertising>(MbAdvertising.class);
        return util.exportExcel(list, "mbAdvertising");
    }

    /**
     * 获取广告管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mbAdvertisingService.selectMbAdvertisingById(id));
    }

    /**
     * 新增广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MbAdvertising mbAdvertising) {
        return toAjax(mbAdvertisingService.insertMbAdvertising(mbAdvertising));
    }

    /**
     * 修改广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MbAdvertising mbAdvertising) {
        return toAjax(mbAdvertisingService.updateMbAdvertising(mbAdvertising));
    }

    /**
     * 删除广告管理
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mbAdvertisingService.deleteMbAdvertisingByIds(ids));
    }

}
